#include "TestBench.h"


TestBench::TestBench(void)
{
}


TestBench::~TestBench(void)
{
}

void TestBench::Init(SpeechRecognizer* rec, string wavPath, string mfccPath, string labelPath)
{
	_rec = rec;
	_wavePath = wavPath;
	_mfccPath = mfccPath;
	_labelPath = labelPath;
}

double TestBench::StartTest(string testFile)
{
	// read out testfile, and for each
	ifstream myfile(testFile);
	string groundtruth;
	string label;
	string line;
	double* mfcc = NULL;

	if (myfile.is_open())
	{
		while ( myfile.good() )
		{
			getline(myfile, line);

			// Load Label
			ifstream labelfile(_labelPath+"\\"+line+".lab");
			getline(labelfile, groundtruth);
			labelfile.close();


			AudioFile f;

			f.LoadMFCCFeatureVectors(_mfccPath+"\\"+line+".txt");
			f.SetLabel(groundtruth);

			label = _rec->ProcessFile(&f);

			if (label.compare(groundtruth) == 0)
			{
				cout << label << " recognized!" << endl;
			}
			else
			{
				cout << "ERROR: " << groundtruth << " recognized as " << label << endl;
			}

		}
	}
	else
	{
		cout << "Error opening testfile.." << endl;
	}

	myfile.close();

	return 0;
}